package org.example.pipeline;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

/**
 * @author hh
 * @since 2024/10/20
 */
public class InPipeline {
    // 内部类，第一个入站处理器
    static class SimpleInHandlerA extends ChannelInboundHandlerAdapter {
        @Override
        public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
            System.out.println("入站处理器A：被回调，消息：" + msg);
            super.channelRead(ctx, msg);
        }
    }

    // 内部类，第二个入站处理器
    static class SimpleInHandlerB extends ChannelInboundHandlerAdapter {
        @Override
        public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
            System.out.println("入站处理器B：被回调");
            super.channelRead(ctx, msg);
            ctx.pipeline().remove(this);
        }
    }

    // 内部类，第三个入站处理器
    static class SimpleInHandlerC extends ChannelInboundHandlerAdapter {
        @Override
        public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
            System.out.println("入站处理器C：被回调");
            super.channelRead(ctx, msg);
        }
    }
}
